﻿using AutoMapper;
using MediatR;
using S.Breed.Domain;
using S.Breed.Domain.Dto;
using S.Breed.Infrastructure.Interface;
using S.Breed.Read.ApI.Application.Command;
using S.Common.Enums.PregnancyTest;

namespace S.Breed.Read.ApI.Application.CommandHandlers
{
    public class BreedEartagListHandler : IRequestHandler<BreedEartagListCommand, List<BreedEartagDto>>,IRequestHandler<BreedShowRamEarCommand, MaternalMatingModel>
    {

        private readonly IMaternalMatingRepository maternalMating;
        private readonly IMapper mapper;

        public BreedEartagListHandler(IMaternalMatingRepository maternalMating, IMapper mapper)
        {
            this.maternalMating = maternalMating;
            this.mapper = mapper;
        }
         
        public async Task<List<BreedEartagDto>> Handle(BreedEartagListCommand request, CancellationToken cancellationToken)
        {
            //获取到配完种的耳号
            List<MaternalMatingModel> childList = maternalMating.GetAllAsync().Result
    .Where(t => t.BreedState == 1)
    .ToList();

            //将Id与耳号赋值
            List<BreedEartagDto> children = childList.Select(x => new BreedEartagDto
            {
                Value = x.BreedId,
                Label = x.EarTag,
            }).ToList();

            return children;
        }
        /// <summary>
        /// 通过种母耳号查信息
        /// </summary>
        public async Task<MaternalMatingModel> Handle(BreedShowRamEarCommand request, CancellationToken cancellationToken)
        {
            return  maternalMating.ShowRamEar(request.Ear);
        }
    }
}
